<? 
$query = "select * from projects";
$result = mysql_query($query);
if ( !$result )
{
	echo ( "<P>Error doing a select: " . mysql_error() . "</P>" );
}
else
{
	// succesful read - how many records ?
	//echo (" Number of rows read " . mysql_num_rows($result)."</br>");
$rr=mysql_num_rows($result); //this is calculating the number of rows read from database and puts it into variable rr
	// set up combo box in form

echo '<form name="form1" id="chooseProject" method="post" action="ed02.php" onsubmit="return validate_form(this)" >';
echo 'Choose Project ';
echo '<select name="project_id" id="project_id">';
// loop over rows, counts the total number and prints them
for ($i=0; $i<$rr; $i++) {
$nextresult = mysql_fetch_array($result);
$project_id = $nextresult['id'];
$project_tag = $nextresult['tag'];
$project_title = $nextresult['title'];


if ($project_id == $_SESSION['pid']) { //uses the $_SESSION['pid'] set by project_get_info.php
	$selected_project = 'selected'; // set the combo box to the selected value
	$selected_tag = $project_tag; //capture the selected tag
	//$_SESSION['tag'] = $project_tag;
	$selected_title = $project_title; //capture the selected title
	//$_SESSION['title'] = $project_title;
	}
else  {	$selected_project = ' ';
	}

//need to have no project selected if session id is zero, or select the option which equals session id
echo '<option value="'.$project_id.'" '.$selected_project.' >'.$project_tag.'</option>';
	} //for
echo '</select>';
echo '<input type="submit" value="Submit" onclick="validate_form(project_id.value)" />';
echo '</form>';
}
// close the connection
//mysql_close($conn); 
?>